package com.jishuo.nontax.web.bill;

import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.bean.GridResult;
import com.jishuo.base.bean.Pagination;
import com.jishuo.base.bean.vo.UserVO;
import com.jishuo.base.config.AppConfig;
import com.jishuo.base.service.UserService;
import com.jishuo.nontax.bean.vo.WaitaffirmVO;
import com.jishuo.nontax.bfc.service.WaitaffirmService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 退付书
 */
@Slf4j
@Controller
@RequestMapping(value = "/bill/waitaffirm", name = "待查")
public class WaitaffirmController {

    @Resource
    private WaitaffirmService waitaffirmService;
    @Resource
    private UserService userService;

    // 页面文件位置
    private String prefix = "bill/";

    @RequestMapping(value = {"waitaffirm"}, name = "待查首页")
    public String index() {
        return prefix + "waitaffirm";
    }

    /**
     * @author hlp
     * @date 2023/3/7 17:42
     * @Description: 待查分页列表
     */
    @ResponseBody
    @RequestMapping(value = "findWaitaffirmPage", name = "待查分页列表")
    public GridResult<WaitaffirmVO> findWaitaffirmPage(WaitaffirmVO waitaffirmVO, Pagination pagination) {
        return new GridResult<>(waitaffirmService.findWaitaFfirmPage(waitaffirmVO, pagination));
    }

    @ResponseBody
    @RequestMapping(value = "sendwaitaffirm", name = "发送待查")
    public BaseResult sendWaitaffirm(String billids, String usercode, String userpwd, HttpSession session) {
        UserVO user = (UserVO) session.getAttribute(AppConfig.LOGIN_USER_SESSION_KEY);
        BaseResult ret = userService.chkAuthUser(usercode, userpwd, user);
        if (!ret.isSuccess()) return ret;
        return waitaffirmService.sendWaitAffirm(billids);
    }

    @ResponseBody
    @RequestMapping(value = "resetwaitaffirm", name = "补发已对账待查")
    public BaseResult resetWaitaffirm(String billids, String usercode, String userpwd, HttpSession session) {
        UserVO user = (UserVO) session.getAttribute(AppConfig.LOGIN_USER_SESSION_KEY);
        BaseResult ret = userService.chkAuthUser(usercode, userpwd, user);
        if (!ret.isSuccess()) return ret;
        return waitaffirmService.resetWaitaffirmInfoByIds(billids);
    }

    @ResponseBody
    @RequestMapping(value = "/cleanwaitaffirm", name = "清理财政端待查")
    public BaseResult cleanwaitaffirm(String accountcode, String paybankdt, String usercode, String userpwd, HttpSession session) {
        UserVO user = (UserVO) session.getAttribute(AppConfig.LOGIN_USER_SESSION_KEY);
        BaseResult ret = userService.chkAuthUser(usercode, userpwd, user);
        if (!ret.isSuccess()) return ret;
        return waitaffirmService.cleanWaitaffirm(accountcode, paybankdt, 0);
    }

    @ResponseBody
    @RequestMapping(value = "/delwaitaffirm", name = "删除待查信息")
    public BaseResult delWaitAffirm(String waitaffirmids) {
        return waitaffirmService.deletewaitaffirm(waitaffirmids);
    }

    @ResponseBody
    @RequestMapping(value = "/savewaitaffirm",name = "新增待查信息")
    public BaseResult saveWaitAffirm(WaitaffirmVO waitaffirmVO) {

        return waitaffirmService.saveWaitAffirm(waitaffirmVO);
    }

    @ResponseBody
    @RequestMapping(value = "/updatewaitaffirm",name = "修改待查信息")
    public BaseResult updatewaitaffirm(WaitaffirmVO waitaffirmVO) {

        return waitaffirmService.updateWaitAffirm(waitaffirmVO);
    }

    @ResponseBody
    @RequestMapping(value = "waitaffirmExport", name = "待查导出")
    public void waitaffirmExport(String accountcode, String paybankdt, HttpServletResponse response) throws IOException {
        waitaffirmService.waitaffirmExport(accountcode, paybankdt, response);
    }
}
